<?php
session_start();
if (isset($_SESSION['openid']) &&  isset($_POST['id']) ){
    include '../c/config.php';
    $jPicName=array(1=>'1-smjyb',2=>'2-xj',3=>'3-dg',4=>'4-sb',5=>'5-yh');
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
    $openid=$_SESSION['openid'];
    
    $query=$mysqli->query("select id,lei from jiang where openid='".$openid."'  limit 0, 1");
    if($query->num_rows>0){
    	$getInfo=$query->fetch_array();
    	
    	$queryU=$mysqli->query("select name,phone,dizhi from uinfo where openid='".$openid."'  limit 0, 1");
    	$getU=$queryU->fetch_array();
    	
    	echo json_encode(array('has'=>'yes','status'=>'work', 'j'=> $getInfo['lei'],'n'=>$jPicName[$getInfo['lei']],
    			'name'=>$getU['name'],'phone'=>$getU['phone'],'dz'=>$getU['dizhi']));
        exit;
   }
   $mysqli->query("insert into log(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."')  ");
   $query=$mysqli->query("select id from log where openid='".$openid."' order by id desc  limit 0, 1");
   $getInfo=$query->fetch_array();
   $getId=$getInfo['id'];
   /**
   if ('test11111111' == $openid){
       $chiName=4;
       $mysqli->query("insert into jiang(openid,lei,createtime) values('".$openid."','".$chiName."','".date("Y-m-d H:i:s")."') ");
       echo json_encode(array('has'=>'no','status'=>'work', 'j'=> $chiName,'n'=>$jPicName[$chiName]));
       exit;
   }  */
   
   $query=$mysqli->query("select name from chi where theid='".$getId."'  limit 0, 1");
   if($query->num_rows>0){
   	  $getChi=$query->fetch_array();
   	  $chiName=$getChi['name'];
   	  $mysqli->query("insert into jiang(openid,lei,createtime) values('".$openid."','".$chiName."','".date("Y-m-d H:i:s")."') ");
   	  echo json_encode(array('has'=>'no','status'=>'work', 'j'=> $chiName,'n'=>$jPicName[$chiName]));
   	  exit;
   }else{
   	$mysqli->query("insert into jiang(openid,lei,createtime) values('".$openid."','5','".date("Y-m-d H:i:s")."') ");
   	echo json_encode(array('has'=>'no','status'=>'work', 'j'=> 5,'n'=>$jPicName[5]));
    exit;
   }
     

}else{
 
    echo json_encode(array('status'=>'not2'));
}